package com.ruoyi.testDeal.service.impl;

import com.deepoove.poi.data.PictureRenderData;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.inspectionItem.InspectionItem;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.ExportWordUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.equ.domain.EquColReruReport;
import com.ruoyi.equ.service.IEquColRetuRecordingService;
import com.ruoyi.equ.service.IEquColrerureportService;
import com.ruoyi.quality.domain.InspectionBasis;
import com.ruoyi.quality.service.IInspectionBasisService;
import com.ruoyi.quality.service.IInspectionItemService;
import com.ruoyi.report.domain.ReportInformation;
import com.ruoyi.report.service.IReportInformationService;
import com.ruoyi.system.service.IJkSbDjInfoService;
import com.ruoyi.system.service.IJkSbGkService;
import com.ruoyi.testDeal.domain.TestDeal;
import com.ruoyi.testDeal.domain.TestDealDto;
import com.ruoyi.testDeal.domain.basic.ReportBasicinfo;
import com.ruoyi.testDeal.domain.basic.ReportHj;
import com.ruoyi.testDeal.domain.basic.ReportTestinfo;
import com.ruoyi.testDeal.domain.basic.YbBasicinfo;
import com.ruoyi.testDeal.domain.equInfo.*;
import com.ruoyi.testDeal.domain.report.*;
import com.ruoyi.testDeal.domain.testItemInfo.ReportTestItem;
import com.ruoyi.testDeal.domain.testItemInfo.YbTestItem;
import com.ruoyi.testDeal.domain.testYs.JkSbGk;
import com.ruoyi.testDeal.domain.testYs.JkSbJg;
import com.ruoyi.testDeal.domain.testYs.JkcrtshjYs;
import com.ruoyi.testDeal.service.*;
import com.ruoyi.testing.domain.EntrustmentAgreement;
import com.ruoyi.testing.domain.EntrustmentAgreementDetail;
import com.ruoyi.testing.service.IEntrustmentAgreementDetailService;
import com.ruoyi.testing.service.IEntrustmentAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;


/**
 * 检测任务信息Service业务层处理
 * 
 * @author lgq
 * @date 2024-3-26
 */
@Service
public class TestDealServiceImpl implements TestDealService
{
    @Autowired
    private IInspectionItemService inspectionItemService;

    @Autowired
    private IInspectionBasisService inspectionBasisService;

    @Autowired
    private IEntrustmentAgreementService agreementService;

    @Autowired
    private IEntrustmentAgreementDetailService entrustmentAgreementDetailService;

    @Autowired
    private IEquColRetuRecordingService equColRetuRecordingService;

    @Autowired
    private IReportBasicinfoService reportBasicinfoService;

    @Autowired
    private IReportHjService reportHjService;

    @Autowired
    private IEquColrerureportService equColrerureportService;

    @Autowired
    private IReportTestinfoService reportTestinfoService;

    @Autowired
    private IReportTestItemService reportTestItemService;

    @Autowired
    private IJkCrtshjInfoService jkCrtshjInfoService;

    @Autowired
    private IJkcrtshjYsService jkcrtshjYsService;

    @Autowired
    private IReportInformationService reportInformationService;

    @Autowired
    private IJkKyjInfoService jkKyjInfoService;

    @Autowired
    private IJkTfjInfoService jkTfjInfoService;

    @Autowired
    private IJkTfjInfoService jkTfjjInfoService;

    @Autowired
    private IJkSbInfoService jkSbInfoService;

    @Autowired
    private IJkSbJgService jkSbJgService;

    @Autowired
    private IJkSbGkService jkSbGkService;

    @Autowired
    private IJkSbDjInfoService jkSbDjInfoService;

    @Autowired
    private IJkFzqInfoService fzqInfoService;

    @Autowired
    private IJkDshshsjDjInfoService jkDshshsjDjInfoService;

    @Autowired
    private IJkDshshsjInfoService jkDshshsjInfoService;

    @Autowired
    private IYbBasicinfoService ybBasicinfoService;

    @Autowired
    private IYbTestItemService ybTestItemService;

    /**
     * 根据检测项目id获取具体检测信息数据
     *
     * @param testId
     */
    @Override
    public TestDeal getTestDeal(String testId) {
        TestDeal testDeal = new TestDeal();
        //根据受检任务id获取检测项信息
        InspectionItem inspectionItem = new InspectionItem();
        inspectionItem.setEquType(testId);
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemList(inspectionItem);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        testDeal.setItemList(inspectionItemTree);
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        testDeal.setInspectionBasisList(inspectionBasisList);
        return testDeal;
    }

    /**
     * 根据项目编号和项目类别获取报告基本参数信息
     *
     * @param agreementNum
     * @param sampleType
     */
    @Override
    public TestDealDto getTestInfoByNumAndType(String agreementNum, String sampleType) {
        //根据项目编号获取项目信息
        EntrustmentAgreement entrustmentAgreement = agreementService.selectEntrustmentAgreementByNum(agreementNum);
        //获取详情信息
        EntrustmentAgreementDetail entrustmentAgreementDetail = entrustmentAgreementDetailService.selectEntrustmentAgreementDetailByNumAndType(agreementNum, sampleType);
        if(Integer.valueOf(entrustmentAgreementDetail.getNums()) > 1) {
            List<Map<String, Object>> bgbhList = new ArrayList<>();
            //截取首个编号
            String start = StringUtils.substringBetween(entrustmentAgreementDetail.getReportNum(), "(", "-");
            //报告编号前半段
            String preBgbh = StringUtils.substring(entrustmentAgreementDetail.getReportNum(), 0, entrustmentAgreementDetail.getReportNum().indexOf("("));
            for (int i = 0; i < Integer.valueOf(entrustmentAgreementDetail.getNums()); i++) {
                Map<String, Object> bgbhMap = new HashMap<>();
                bgbhMap.put("reportNum", preBgbh + String.format("%03d",(Integer.valueOf(start) + i)));
                bgbhList.add(bgbhMap);
            }
            entrustmentAgreementDetail.setBgbhList(bgbhList);
        }
        entrustmentAgreement.setEntrustmentAgreementDetail(entrustmentAgreementDetail);
        //根据委托编号和样品类别获取设备出库信息
        List<EquColReruReport> equColReruReportList = equColRetuRecordingService.selectEquColRetuRecordingByNumAndType(agreementNum, sampleType);
        //处理数据
        for(EquColReruReport equColReruReport : equColReruReportList) {
            String[] grade = equColReruReport.getEquGrade().split("；");
            StringBuffer sf = new StringBuffer("");
            if(grade.length > 1) {
                for(int i = 0 ; i < grade.length; i++) {
                    if(i == grade.length - 1) {
                        sf = sf.append(grade[i]);
                    }else {
                        sf = sf.append(grade[i] + "；\n");
                    }
                }
            }
            if(!sf.toString().isEmpty()) {
                equColReruReport.setEquGrade(sf.toString());
            }

        }
        TestDealDto testDealDto = new TestDealDto();
        testDealDto.setAgreementNum(agreementNum);
        testDealDto.setSampleType(sampleType);
        testDealDto.setEntrustmentAgreement(entrustmentAgreement);
        testDealDto.setEquColReruReportList(equColReruReportList);
        return testDealDto;
    }

    /**
     * 非煤缠绕提升机报告内容保存
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkCrtshj(JkCrtshjReportData jkCrtshjReportData) {
        //根据报告编号删除原数据
        delJkCrtshjInfoByReportNum(jkCrtshjReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkCrtshjReportData.getReportNum();
        String shjdw = jkCrtshjReportData.getReportBasicInfo().getShjdw();
        String jylb = jkCrtshjReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkCrtshjReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkCrtshjReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkCrtshjReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkCrtshjReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkCrtshjReportData.getSampleType());
        reportInformation.setEquName(jkCrtshjReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkCrtshjReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkCrtshjReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkCrtshjReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkCrtshjReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkCrtshjReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkCrtshjReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkCrtshjReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkCrtshjReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkCrtshjReportData.getEquColReruReportList() && !jkCrtshjReportData.getEquColReruReportList().isEmpty()) {
            jkCrtshjReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkCrtshjReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkCrtshjReportData.getReportTestInfo().setReportNum(reportNum);
            jkCrtshjReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkCrtshjReportData.getReportTestInfo().setJylb(jylb);
            jkCrtshjReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkCrtshjReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkCrtshjReportData.getReportTestItemList() && !jkCrtshjReportData.getReportTestItemList().isEmpty()) {
            jkCrtshjReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkCrtshjReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != reportNum) {
            jkCrtshjReportData.getJkCrtshjInfo().setReportNum(reportNum);
            jkCrtshjInfoService.insertJkCrtshjInfo(jkCrtshjReportData.getJkCrtshjInfo());
        }
        //保存验证结果
        if(null != reportNum) {
            jkCrtshjReportData.getJkCrtshjYs().setReportNum(reportNum);
            jkcrtshjYsService.insertJkcrtshjYs(jkCrtshjReportData.getJkCrtshjYs());
        }
        return 1;
    }

    /**
     * 非煤缠绕提升机报告导入
     *
     * @param jkCrtshjReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String importJkCrtshj(JkCrtshjReportData jkCrtshjReportData) {
        // 报告模板名称
        String template = jkCrtshjReportData.getTempId();
        //保存结果内容
        saveJkCrtshj(jkCrtshjReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkCrtshjReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkCrtshjReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkCrtshjReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkCrtshjReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkCrtshjReportData.getReportTestInfo();
            params.put("设备型号", reportTestinfo.getShbxh());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkCrtshjReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("报告检测日期", DateUtils.formatDate(jkCrtshjReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("制造单位", reportTestinfo.getZhzdw());
            params.put("检测地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位名称", jkCrtshjReportData.getReportBasicInfo().getShjdw());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkCrtshjReportData.getReportHj()) {
            ReportHj reportHj = jkCrtshjReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("相对湿度", reportHj.getXdshd());
            params.put("检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.YYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkCrtshjReportData.getEquColReruReportList() && !jkCrtshjReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkCrtshjReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkCrtshjReportData.getJkCrtshjInfo()) {
            JkCrtshjInfo jkCrtshjInfo = jkCrtshjReportData.getJkCrtshjInfo();
            params.put("提升机型号", jkCrtshjInfo.getTshjxh());
            params.put("提升机用途", jkCrtshjInfo.getTshjyt());
            params.put("制造单位", jkCrtshjInfo.getZhzdw());
            params.put("出厂日期", DateUtils.formatDate(jkCrtshjInfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("使用场所", jkCrtshjInfo.getShycs());
            params.put("设备编号", jkCrtshjInfo.getShbbh());
            params.put("提升高度", jkCrtshjInfo.getTshgd());
            params.put("井筒倾角", jkCrtshjInfo.getJtqj());
            params.put("滚筒个数", jkCrtshjInfo.getGtgs());
            params.put("滚筒宽度", jkCrtshjInfo.getGtkd());
            params.put("滚筒直径", jkCrtshjInfo.getGsshzj());
            params.put("钢丝绳型号", jkCrtshjInfo.getGsshxh());
            params.put("钢丝绳直径", jkCrtshjInfo.getGsshzj());
            params.put("尾绳型号", jkCrtshjInfo.getWshxh());
            params.put("减速器型号", jkCrtshjInfo.getJsqxh());
            params.put("减速器变速比", jkCrtshjInfo.getJsqbsb());
            params.put("减速器扭矩", jkCrtshjInfo.getJsqnj());
            params.put("电控系统型号", jkCrtshjInfo.getDkxtxh());
            params.put("电控系统生产单位", jkCrtshjInfo.getDkxtshcdw());
            params.put("电控系统生产日期", DateUtils.formatDate(jkCrtshjInfo.getDkxtshcrq(), DateUtils.YYYY_MM_DD));
            params.put("提升容器名称", jkCrtshjInfo.getTshrqmc());
            params.put("提升容器数量", jkCrtshjInfo.getTshrqshl());
            params.put("提升容器型号", jkCrtshjInfo.getTshrqxh());
            params.put("箕斗自重", jkCrtshjInfo.getJdzzh());
            params.put("箕斗载重", jkCrtshjInfo.getJdzaiz());
            params.put("电动机型号", jkCrtshjInfo.getDdjxh());
            params.put("电动机功率", jkCrtshjInfo.getDdjgl());
            params.put("电动机生产日期", DateUtils.formatDate(jkCrtshjInfo.getDdjshcrq(), DateUtils.YYYY_MM_DD));
            params.put("电动机转数", jkCrtshjInfo.getDdjzhs());
            params.put("电动机出厂编号", jkCrtshjInfo.getDdjchcbh());
            params.put("电动机生产厂家", jkCrtshjInfo.getDdjshccj());
            params.put("天轮型号", jkCrtshjInfo.getTlxh());
            params.put("天轮布置形式", jkCrtshjInfo.getTlbzhxs());
            params.put("天轮直径", jkCrtshjInfo.getTlzhj());
            params.put("天轮围包角", jkCrtshjInfo.getTlwbj());
        }
        //检测检验项目表
        List<Map<String, Object>> itemList = new ArrayList<>();
        if(null != jkCrtshjReportData.getReportTestItemList() && !jkCrtshjReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkCrtshjReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put(i + 1 + "实测结果", reportTestItemList.get(i).getShcjg());
                    params.put(i + 1 + "判定结果", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                    params.put(i + 1 + "备注", reportTestItemList.get(i).getRemark());
                }
            }
        }
        //检验报告验算
        if(null != jkCrtshjReportData.getJkCrtshjYs()) {
            JkcrtshjYs jkcrtshjYs = jkCrtshjReportData.getJkCrtshjYs();
            params.put("Qd", jkcrtshjYs.getGsshpdllh());
            params.put("a", jkcrtshjYs.getJdqj());
            params.put("Q", jkcrtshjYs.getQdzizh());
            params.put("Qz", jkcrtshjYs.getQdzzh());
            params.put("p", jkcrtshjYs.getGsshdwcdzhl());
            params.put("L", jkcrtshjYs.getTshgd());
            params.put("F1", jkcrtshjYs.getQdzlxsh());
            params.put("F2", jkcrtshjYs.getGsshzlxsh());
            params.put("最大静张力公式", jkcrtshjYs.getZdjzhlgsh());
            params.put("最大静张力", jkcrtshjYs.getZdjzhl());
            params.put("Fjm", jkcrtshjYs.getYxzdjzhl());
            params.put("最大静张力结论", jkcrtshjYs.getZdjzhljg());
            params.put("最大静张力差", jkcrtshjYs.getZdjzhlc());
            params.put("Fjc", jkcrtshjYs.getYxzdjzhlc());
            params.put("最大静张力差结果", jkcrtshjYs.getYxzdjzhlcjg());
            params.put("钢丝绳安全系数", jkcrtshjYs.getGsshaqxsh());
            params.put("钢丝绳安全系数结论", jkcrtshjYs.getGsshaqxshjg());
            params.put("最大运行速度", jkcrtshjYs.getZdyxsd());
            params.put("提升时间", jkcrtshjYs.getTshsj());
            params.put("运行速度图", new PictureRenderData(520, 270, jkcrtshjYs.getYxsdImg().replace( "/profile", RuoYiConfig.getProfile())));
            params.put("制动力矩", jkcrtshjYs.getZhdlj());
            params.put("旋转力矩", jkcrtshjYs.getXzhljgs());
            params.put("旋转力矩结果", jkcrtshjYs.getXzhlj());
            params.put("K值公式", jkcrtshjYs.getZhdljKgs());
            params.put("K值结果", jkcrtshjYs.getZhdljK());
            params.put("K值结论", jkcrtshjYs.getZhdljKjg());
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("检验用设备和仪器备注", jkCrtshjReportData.getEquColReruReportList().get(0).getRemark());
        params.put("建议", jkCrtshjReportData.getJyi());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkCrtshjReportData.getReportNum() + "-jkCrtshj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 根据报告编号获取详细信息
     *
     * @param reportNum
     * @param testId
     */
    @Override
    public JkCrtshjReportData getInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkCrtshjReportData jkCrtshjReportData = new JkCrtshjReportData();
        jkCrtshjReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkCrtshjReportData.setReportType(reportInformation.getReportType());
        jkCrtshjReportData.setSampleType(reportInformation.getSampleType());
        jkCrtshjReportData.setReportNum(reportInformation.getReportNum());
        jkCrtshjReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkCrtshjReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkCrtshjReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkCrtshjReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkCrtshjReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤缠绕提升机参数信息
        JkCrtshjInfo jkCrtshjInfo = jkCrtshjInfoService.selectJkCrtshjInfoByReportNum(reportNum);
        jkCrtshjReportData.setJkCrtshjInfo(jkCrtshjInfo);
        //根据报告编号获取验算测试项
        JkcrtshjYs jkcrtshjYs = jkcrtshjYsService.selectJkcrtshjYsByReportNum(reportNum);
        jkCrtshjReportData.setJkCrtshjYs(jkcrtshjYs);
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkCrtshjReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkCrtshjReportData.setInspectionBasisList(inspectionBasisList);
        return jkCrtshjReportData;
    }

    /**
     * 根据报告编号删除详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkCrtshjInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤缠绕提升机参数信息
        jkCrtshjInfoService.deleteJkCrtshjInfoByReportNum(reportNum);
        //根据报告编号删除验算测试项
        jkcrtshjYsService.deleteJkcrtshjYsByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤空压机数据保存
     *
     * @param jkKyjReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkKyj(JkKyjReportData jkKyjReportData) {
        //根据报告编号删除原数据
        delJkKyjInfoByReportNum(jkKyjReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkKyjReportData.getReportNum();
        String shjdw = jkKyjReportData.getReportBasicInfo().getShjdw();
        String jylb = jkKyjReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkKyjReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkKyjReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkKyjReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkKyjReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkKyjReportData.getSampleType());
        reportInformation.setEquName(jkKyjReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkKyjReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkKyjReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkKyjReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkKyjReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkKyjReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkKyjReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkKyjReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkKyjReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkKyjReportData.getEquColReruReportList() && !jkKyjReportData.getEquColReruReportList().isEmpty()) {
            jkKyjReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkKyjReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkKyjReportData.getReportTestInfo().setReportNum(reportNum);
            jkKyjReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkKyjReportData.getReportTestInfo().setJylb(jylb);
            jkKyjReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkKyjReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkKyjReportData.getReportTestItemList() && !jkKyjReportData.getReportTestItemList().isEmpty()) {
            jkKyjReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkKyjReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != jkKyjReportData.getJkKyjInfo()) {
            jkKyjReportData.getJkKyjInfo().setReportNum(reportNum);
            jkKyjInfoService.insertJkKyjInfo(jkKyjReportData.getJkKyjInfo());
        }
        return 1;
    }

    /**
     * 根据报告编号删除空压机详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkKyjInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤空压机参数信息
        jkKyjInfoService.deleteJkKyjInfoByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    @Override
    public JkKyjReportData getKyjInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkKyjReportData jkKyjReportData = new JkKyjReportData();
        jkKyjReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkKyjReportData.setReportType(reportInformation.getReportType());
        jkKyjReportData.setSampleType(reportInformation.getSampleType());
        jkKyjReportData.setReportNum(reportInformation.getReportNum());
        jkKyjReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkKyjReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkKyjReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkKyjReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkKyjReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤空压机参数信息
        JkKyjInfo jkKyjInfo = jkKyjInfoService.selectJkKyjInfoByReportNum(reportNum);
        jkKyjReportData.setJkKyjInfo(jkKyjInfo);
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkKyjReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkKyjReportData.setInspectionBasisList(inspectionBasisList);
        return jkKyjReportData;
    }

    @Override
    public JkTfjReportData getTfjInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkTfjReportData jkTfjReportData = new JkTfjReportData();
        jkTfjReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkTfjReportData.setReportType(reportInformation.getReportType());
        jkTfjReportData.setSampleType(reportInformation.getSampleType());
        jkTfjReportData.setReportNum(reportInformation.getReportNum());
        jkTfjReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkTfjReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkTfjReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkTfjReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkTfjReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤空压机参数信息
        JkTfjInfo jkTfjInfo = jkTfjjInfoService.selectJkTfjInfoByReportNum(reportNum);
        jkTfjReportData.setJkTfjInfo(jkTfjInfo);
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkTfjReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkTfjReportData.setInspectionBasisList(inspectionBasisList);
        return jkTfjReportData;
    }

    /**
     * 根据报告编号获取水泵报告详情
     *
     * @param reportNum
     * @param testId
     * @return
     */
    @Override
    public JkSbReportData getSbInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkSbReportData jkSbReportData = new JkSbReportData();
        jkSbReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkSbReportData.setReportType(reportInformation.getReportType());
        jkSbReportData.setSampleType(reportInformation.getSampleType());
        jkSbReportData.setReportNum(reportInformation.getReportNum());
        jkSbReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkSbReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkSbReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkSbReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkSbReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤水泵参数信息
        JkSbInfo jkSbInfo = jkSbInfoService.selectJkSbInfoByReportNum(reportNum);
        jkSbReportData.setJkSbInfo(jkSbInfo);
        jkSbReportData.setAzhrq(jkSbInfo.getAzhrq());
        jkSbReportData.setPtdj(jkSbInfo.getPtdj());
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkSbReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkSbReportData.setInspectionBasisList(inspectionBasisList);
        //水泵结果信息
        JkSbJg jkSbJg = jkSbJgService.selectJkSbJgByReportNum(reportNum);
        jkSbReportData.setJkSbJg(jkSbJg);
        //水泵工况点信息
        List<JkSbGk> jkSbGks = jkSbGkService.selectJkSbGkByReportNum(reportNum);
        jkSbReportData.setJkSbGkList(jkSbGks);
        //水泵电机信息
        List<JkSbDjInfo> jkSbDjInfoList = jkSbDjInfoService.selectJkSbDjInfoByReportNum(reportNum);
        jkSbReportData.setJkSbDjInfoList(jkSbDjInfoList);
        return jkSbReportData;
    }

    /**
     * 根据报告编号获取防坠器报告详情
     *
     * @param reportNum
     * @param testId
     * @return
     */
    @Override
    public JkFzqReportData getFzqInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkFzqReportData jkFzqReportData = new JkFzqReportData();
        jkFzqReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkFzqReportData.setReportType(reportInformation.getReportType());
        jkFzqReportData.setSampleType(reportInformation.getSampleType());
        jkFzqReportData.setReportNum(reportInformation.getReportNum());
        jkFzqReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkFzqReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkFzqReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkFzqReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkFzqReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤空压机参数信息
        JkFzqInfo jkFzqInfo = fzqInfoService.selectJkFzqInfoByReportNum(reportNum);
        jkFzqReportData.setJkFzqInfo(jkFzqInfo);
        jkFzqReportData.setCpzt(jkFzqInfo.getCpzt());
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkFzqReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkFzqReportData.setInspectionBasisList(inspectionBasisList);
        return jkFzqReportData;
    }

    /**
     * 根据报告编号获取带式输送机报告详情
     *
     * @param reportNum
     * @param testId
     * @return
     */
    @Override
    public JkDshshsjReportData getDshshsjInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkDshshsjReportData jkDshshsjReportData = new JkDshshsjReportData();
        jkDshshsjReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkDshshsjReportData.setReportType(reportInformation.getReportType());
        jkDshshsjReportData.setSampleType(reportInformation.getSampleType());
        jkDshshsjReportData.setReportNum(reportInformation.getReportNum());
        jkDshshsjReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkDshshsjReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkDshshsjReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkDshshsjReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkDshshsjReportData.setEquColReruReportList(equColReruReportList);
        //根据报告编号获取非煤带式输送机参数信息
        JkDshshsjInfo jkDshshsjInfo = jkDshshsjInfoService.selectJkDshshsjInfoByReportNum(reportNum);
        jkDshshsjReportData.setJkDshshsjInfo(jkDshshsjInfo);
        //根据报告编号获取电机数据
        List<JkDshshsjDjInfo> jkDshshsjDjInfos = jkDshshsjDjInfoService.selectJkDshshsjDjInfoByReportNum(reportNum);
        jkDshshsjReportData.setJkDshshsjDjInfoList(jkDshshsjDjInfos);
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkDshshsjReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkDshshsjReportData.setInspectionBasisList(inspectionBasisList);
        return jkDshshsjReportData;
    }

    /**
     * 根据报告编号获取矿山监测监控系统报告详情
     *
     * @param reportNum
     * @param testId
     * @return
     */
    @Override
    public JkKshjcjkxtReportData getKshjcjkxtInfoByReportNum(String reportNum, String testId) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        JkKshjcjkxtReportData jkKshjcjkxtReportData = new JkKshjcjkxtReportData();
        jkKshjcjkxtReportData.setAgreementNum(reportInformation.getAgreementNum());
        jkKshjcjkxtReportData.setReportType(reportInformation.getReportType());
        jkKshjcjkxtReportData.setSampleType(reportInformation.getSampleType());
        jkKshjcjkxtReportData.setReportNum(reportInformation.getReportNum());
        jkKshjcjkxtReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        ReportBasicinfo reportBasicinfo = reportBasicinfoService.selectReportBasicinfoByReportNum(reportNum);
        jkKshjcjkxtReportData.setReportBasicInfo(reportBasicinfo);
        //根据报告编号获取检测检验报告信息
        ReportTestinfo reportTestinfo = reportTestinfoService.selectReportTestinfoByReportNum(reportNum);
        jkKshjcjkxtReportData.setReportTestInfo(reportTestinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        jkKshjcjkxtReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        jkKshjcjkxtReportData.setEquColReruReportList(equColReruReportList);
        //树形检测检验项数据
        List<InspectionItem> inspectionItemList = inspectionItemService.selectInspectionItemByReport(reportNum, testId);
        List<InspectionItem> inspectionItemTree = inspectionItemService.buildInspectionItemTree(inspectionItemList);
        jkKshjcjkxtReportData.setItemList(inspectionItemTree);
        //检测标准信息
        //根据受检任务id获取检测内容信息
        InspectionBasis inspectionBasis = new InspectionBasis();
        inspectionBasis.setEquType(testId);
        List<InspectionBasis> inspectionBasisList = inspectionBasisService.selectInspectionBasisList(inspectionBasis);
        jkKshjcjkxtReportData.setInspectionBasisList(inspectionBasisList);
        return jkKshjcjkxtReportData;
    }

    /**
     * 根据报告编号获取仪表报告详情
     *
     * @param reportNum
     * @return
     */
    @Override
    public YbReportData getYbInfoByReportNum(String reportNum) {
        //根据报告编号获取报告基本信息
        ReportInformation reportInformation = reportInformationService.selectReportInformationByNum(reportNum);
        YbReportData ybReportData = new YbReportData();
        ybReportData.setAgreementNum(reportInformation.getAgreementNum());
        ybReportData.setReportType(reportInformation.getReportType());
        ybReportData.setSampleType(reportInformation.getSampleType());
        ybReportData.setReportNum(reportInformation.getReportNum());
        ybReportData.setJyi(reportInformation.getRemark());
        //根据报告编号获取基本信息
        YbBasicinfo ybBasicinfo = ybBasicinfoService.selectYbBasicinfoByReportNum(reportNum);
        ybReportData.setYbBasicInfo(ybBasicinfo);
        //根据报告编号获取检测检验环境信息
        ReportHj reportHj = reportHjService.selectReportHjByReportNum(reportNum);
        ybReportData.setReportHj(reportHj);
        //根据报告编号获取检测检验设备仪器信息
        List<EquColReruReport> equColReruReportList = equColrerureportService.selectEquColrerureportByReportNum(reportNum);
        ybReportData.setEquColReruReportList(equColReruReportList);
        //树形检测检验项数据
        List<YbTestItem> ybTestItemList = ybTestItemService.selectYbTestItemByReportNum(reportNum);
        ybReportData.setYbTestItemList(ybTestItemList);
        return ybReportData;
    }

    /**
     * 非煤空压机报告导入
     *
     * @param jkKyjReportData
     */
    @Override
    public String importJkKyj(JkKyjReportData jkKyjReportData) {
        // 报告模板名称
        String template = jkKyjReportData.getTempId();
        //保存结果内容
        saveJkKyj(jkKyjReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkKyjReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkKyjReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkKyjReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkKyjReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkKyjReportData.getReportTestInfo();
            params.put("设备名称", jkKyjReportData.getReportBasicInfo().getShbmc());
            params.put("设备型号", reportTestinfo.getShbxh());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkKyjReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("报告检验日期", DateUtils.formatDate(jkKyjReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("受检单位名称", jkKyjReportData.getReportBasicInfo().getShjdw());
            params.put("规格型号", jkKyjReportData.getReportBasicInfo().getXhgg());
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("生产厂家", reportTestinfo.getZhzdw());
            params.put("检验地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkKyjReportData.getReportHj()) {
            ReportHj reportHj = jkKyjReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkKyjReportData.getEquColReruReportList() && !jkKyjReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkKyjReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkKyjReportData.getJkKyjInfo()) {
            JkKyjInfo jkKyjInfo = jkKyjReportData.getJkKyjInfo();
            params.put("空压机型号", jkKyjInfo.getXh());
            params.put("排气压力", jkKyjInfo.getPqyl());
            params.put("空压机转速", jkKyjInfo.getZhs());
            params.put("空压机出厂编号", jkKyjInfo.getChcbh());
            params.put("空压机轴功率", jkKyjInfo.getZhgl());
            params.put("出厂日期", DateUtils.formatDate(jkKyjInfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("空压机排气量", jkKyjInfo.getPql());
            params.put("空压机制造厂", jkKyjInfo.getZhzc());
            params.put("电动机型号", jkKyjInfo.getDjxh());
            params.put("电动机功率", jkKyjInfo.getDjgl());
            params.put("电动机转速", jkKyjInfo.getDjzhs());
            params.put("电动机电压", jkKyjInfo.getDjdy());
            params.put("电动机电流", jkKyjInfo.getDjdl());
            params.put("电动机效率", jkKyjInfo.getDjxl());
            params.put("电动机频率", jkKyjInfo.getDjpl());
            params.put("电动机出厂日期", DateUtils.formatDate(jkKyjInfo.getDjchcrq(), DateUtils.YYYY_MM_DD));
            params.put("电动机出厂编号", jkKyjInfo.getDjchcbh());
            params.put("电动机制造厂", jkKyjInfo.getDjzhzc());
            params.put("冷却方式", jkKyjInfo.getLqfs());
            params.put("传动方式", jkKyjInfo.getChdfs());
        }
        //检测检验项目表
        if(null != jkKyjReportData.getReportTestItemList() && !jkKyjReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkKyjReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put(i + 1 + "实测结果", reportTestItemList.get(i).getShcjg());
                    params.put(i + 1 + "单项判定", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("建议", jkKyjReportData.getJyi());
        params.put("检验用设备和仪器备注", jkKyjReportData.getEquColReruReportList().get(0).getRemark());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkKyjReportData.getReportNum() + "-jkKyj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 非煤通风机数据保存
     *
     * @param jkTfjReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkTfj(JkTfjReportData jkTfjReportData) {
        //根据报告编号删除原数据
        delJkTfjInfoByReportNum(jkTfjReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkTfjReportData.getReportNum();
        String shjdw = jkTfjReportData.getReportBasicInfo().getShjdw();
        String jylb = jkTfjReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkTfjReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkTfjReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkTfjReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkTfjReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkTfjReportData.getSampleType());
        reportInformation.setEquName(jkTfjReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkTfjReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkTfjReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkTfjReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkTfjReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkTfjReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkTfjReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkTfjReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkTfjReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkTfjReportData.getEquColReruReportList() && !jkTfjReportData.getEquColReruReportList().isEmpty()) {
            jkTfjReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkTfjReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkTfjReportData.getReportTestInfo().setReportNum(reportNum);
            jkTfjReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkTfjReportData.getReportTestInfo().setJylb(jylb);
            jkTfjReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkTfjReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkTfjReportData.getReportTestItemList() && !jkTfjReportData.getReportTestItemList().isEmpty()) {
            jkTfjReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkTfjReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != jkTfjReportData.getJkTfjInfo()) {
            jkTfjReportData.getJkTfjInfo().setReportNum(reportNum);
            jkTfjInfoService.insertJkTfjInfo(jkTfjReportData.getJkTfjInfo());
        }
        return 1;
    }

    /**
     * 根据报告编号删除通风机详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkTfjInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤通风机参数信息
        jkTfjInfoService.deleteJkTfjInfoByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤通风机报告导入
     *
     * @param jkTfjReportData
     */
    @Override
    public String importJkTfj(JkTfjReportData jkTfjReportData) {
        // 报告模板名称
        String template = jkTfjReportData.getTempId();
        //保存结果内容
        saveJkTfj(jkTfjReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkTfjReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkTfjReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkTfjReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkTfjReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkTfjReportData.getReportTestInfo();
            params.put("设备名称", jkTfjReportData.getReportBasicInfo().getShbmc());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkTfjReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("报告检验日期", DateUtils.formatDate(jkTfjReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("受检单位名称", jkTfjReportData.getReportBasicInfo().getShjdw());
            params.put("规格型号", jkTfjReportData.getReportBasicInfo().getXhgg());
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("生产厂家", reportTestinfo.getZhzdw());
            params.put("检验地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkTfjReportData.getReportHj()) {
            ReportHj reportHj = jkTfjReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkTfjReportData.getEquColReruReportList() && !jkTfjReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkTfjReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkTfjReportData.getJkTfjInfo()) {
            JkTfjInfo jkTfjInfo = jkTfjReportData.getJkTfjInfo();
            params.put("通风机规格型号", jkTfjInfo.getTfjggxh());
            params.put("通风机标称风量", jkTfjInfo.getTfjbcfl());
            params.put("通风机标称风压", jkTfjInfo.getTfjbcfy());
            params.put("通风机额定转速", jkTfjInfo.getTfjedzhs());
            params.put("通风机传动方式", jkTfjInfo.getTfjchdfs());
            params.put("通风机生产厂家", jkTfjInfo.getTfjschcj());
            params.put("通风机出厂日期", DateUtils.formatDate(jkTfjInfo.getTfjchcrq(), DateUtils.YYYY_MM_DD));
            params.put("通风机出厂编号", jkTfjInfo.getTfjchcbh());
            params.put("电动机规格型号", jkTfjInfo.getDjggxh());
            params.put("电动机额定功率", jkTfjInfo.getDjedgl());
            params.put("电动机定子电压", jkTfjInfo.getDjdzdy());
            params.put("电动机定子电流", jkTfjInfo.getDjdzdl());
            params.put("电动机额定转速", jkTfjInfo.getDjedzhs());
            params.put("电动机额定效率", jkTfjInfo.getDjedxl());
            params.put("电动机生产厂家", jkTfjInfo.getDjschcj());
            params.put("电动机出厂日期", DateUtils.formatDate(jkTfjInfo.getDjchcrq(), DateUtils.YYYY_MM_DD));
        }
        //检测检验项目表
        if(null != jkTfjReportData.getReportTestItemList() && !jkTfjReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkTfjReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put((i + 1) + "实测结果", reportTestItemList.get(i).getShcjg());
                    params.put((i + 1) + "单项判定", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                    params.put((i + 1) + "备注", reportTestItemList.get(i).getRemark());
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("建议", jkTfjReportData.getJyi());
        params.put("检验用设备和仪器备注", jkTfjReportData.getEquColReruReportList().get(0).getRemark());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkTfjReportData.getReportNum() + "-jkTfj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 非煤水泵数据保存
     *
     * @param jkSbReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkSb(JkSbReportData jkSbReportData) {
        //根据报告编号删除原数据
        delJkSbInfoByReportNum(jkSbReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkSbReportData.getReportNum();
        String shjdw = jkSbReportData.getReportBasicInfo().getShjdw();
        String jylb = jkSbReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkSbReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkSbReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkSbReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkSbReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkSbReportData.getSampleType());
        reportInformation.setEquName(jkSbReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkSbReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkSbReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkSbReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkSbReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkSbReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkSbReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkSbReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkSbReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkSbReportData.getEquColReruReportList() && !jkSbReportData.getEquColReruReportList().isEmpty()) {
            jkSbReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkSbReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkSbReportData.getReportTestInfo().setReportNum(reportNum);
            jkSbReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkSbReportData.getReportTestInfo().setJylb(jylb);
            jkSbReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkSbReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkSbReportData.getReportTestItemList() && !jkSbReportData.getReportTestItemList().isEmpty()) {
            jkSbReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkSbReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != jkSbReportData.getJkSbInfo()) {
            jkSbReportData.getJkSbInfo().setReportNum(reportNum);
            jkSbReportData.getJkSbInfo().setAzhrq(jkSbReportData.getAzhrq());
            jkSbReportData.getJkSbInfo().setPtdj(jkSbReportData.getPtdj());
            jkSbInfoService.insertJkSbInfo(jkSbReportData.getJkSbInfo());
        }
        //保存结果信息
        if(null != jkSbReportData.getJkSbJg()) {
            jkSbReportData.getJkSbJg().setReportNum(reportNum);
            jkSbJgService.insertJkSbJg(jkSbReportData.getJkSbJg());
        }
        //保存电机信息
        if(null != jkSbReportData.getJkSbDjInfoList() && ! jkSbReportData.getJkSbDjInfoList().isEmpty()) {
            jkSbReportData.getJkSbDjInfoList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            jkSbDjInfoService.batchJkSbDjInfo(jkSbReportData.getJkSbDjInfoList());
        }
        //保存工况信息
        if(null != jkSbReportData.getJkSbGkList() && ! jkSbReportData.getJkSbGkList().isEmpty()) {
            jkSbReportData.getJkSbGkList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            jkSbGkService.batchJkSbGk(jkSbReportData.getJkSbGkList());
        }
        return 1;
    }

    /**
     * 根据报告编号删除水泵详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkSbInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤水泵参数信息
        jkSbInfoService.deleteJkSbInfoByReportNum(reportNum);
        //根据报告编号删除水泵工况信息
        jkSbGkService.deleteJkSbGkByReportNum(reportNum);
        //根据报告编号删除水泵电机信息
        jkSbDjInfoService.deleteJkSbDjInfoByReportNum(reportNum);
        //根据报告编号删除水泵结果信息
        jkSbJgService.deleteJkSbJgByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤水泵报告导入
     *
     * @param jkSbReportData
     */
    @Override
    public String importJkSb(JkSbReportData jkSbReportData) {
        // 报告模板名称
        String template = jkSbReportData.getTempId();
        //保存结果内容
        saveJkSb(jkSbReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkSbReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkSbReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkSbReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkSbReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkSbReportData.getReportTestInfo();
            params.put("规格型号", jkSbReportData.getReportBasicInfo().getXhgg());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkSbReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("生产厂家", reportTestinfo.getZhzdw());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("报告检测日期", DateUtils.formatDate(jkSbReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("检测地点", reportTestinfo.getJcdd());
            params.put("安装日期", DateUtils.formatDate(jkSbReportData.getAzhrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("配套电机", jkSbReportData.getPtdj());
            params.put("受检单位名称", jkSbReportData.getReportBasicInfo().getShjdw());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkSbReportData.getReportHj()) {
            ReportHj reportHj = jkSbReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("环境检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkSbReportData.getEquColReruReportList() && !jkSbReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkSbReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkSbReportData.getJkSbInfo()) {
            JkSbInfo jkSbInfo = jkSbReportData.getJkSbInfo();
            params.put("水泵规格型号", jkSbInfo.getSbxh());
            params.put("水泵额定扬程", jkSbInfo.getSbedyc());
            params.put("水泵额定流量", jkSbInfo.getSbedll());
            params.put("水泵转速", jkSbInfo.getSbzhs());
            params.put("水泵效率", jkSbInfo.getSbxl());
            params.put("水泵安标证号", jkSbInfo.getSbabzh());
            params.put("水泵出厂日期", DateUtils.formatDate(jkSbInfo.getSbchcrq(), DateUtils.YYYY_MM_DD));
            params.put("水泵出厂编号", jkSbInfo.getSbchcbh());
            params.put("水泵生产厂家", jkSbInfo.getSbshchcj());

            params.put("电机型号", jkSbInfo.getDjxh());
            params.put("电机额定功率", jkSbInfo.getDjedgl());
            params.put("电机额定电压", jkSbInfo.getDjeddy());
            params.put("电机额定电流", jkSbInfo.getDjeddl());
            params.put("电机转速", jkSbInfo.getDjzhs());
            params.put("电机生产厂家", jkSbInfo.getDjschcj());
            params.put("电机出厂日期", DateUtils.formatDate(jkSbInfo.getDjchcrq(), DateUtils.YYYY_MM_DD));
            params.put("电机出厂编号", jkSbInfo.getDjchcbh());
            params.put("电机接法", jkSbInfo.getDjjf());
            params.put("电机绝缘等级", jkSbInfo.getDjjydj());
            params.put("电机防爆合格证号", jkSbInfo.getDjfbhgzhh());
            params.put("电机安标证号", jkSbInfo.getDjabzhh());
            params.put("电机功率因数", jkSbInfo.getDjcos());
            params.put("电机效率", jkSbInfo.getDjxl());

            params.put("吸水管内径", jkSbInfo.getXshgnj());
            params.put("矿井排水管内径", jkSbInfo.getPshgnj());
            params.put("表位差", jkSbInfo.getBwch());
            params.put("矿井排水高度", jkSbInfo.getPshgd());
            params.put("矿井最大涌水量", jkSbInfo.getKjzhdyshl());
            params.put("矿井正常涌水量", jkSbInfo.getKjzhcyshl());
            params.put("水仓容积", jkSbInfo.getShcrj());
        }
        //检测检验项目表
        if(null != jkSbReportData.getReportTestItemList() && !jkSbReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkSbReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put((i + 1) + "实测结果", reportTestItemList.get(i).getShcjg());
                    params.put((i + 1) + "单项判定", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                }
            }
        }
        //水泵检验数据及结果信息
        if(null != jkSbReportData.getJkSbJg()) {
            JkSbJg jkSbJg = jkSbReportData.getJkSbJg();
            params.put("流量实测", jkSbJg.getLl());
            params.put("真空表压力实测", jkSbJg.getZkbdsh());
            params.put("压力表读书实测", jkSbJg.getYlbdsh());
            params.put("表位差实测", jkSbJg.getBwch());
            params.put("吸水管内径实测", jkSbJg.getXshgnj());
            params.put("排水管内径实测", jkSbJg.getPshgnj());
            params.put("扬程计算", jkSbJg.getYch());
            params.put("吸水高度实测", jkSbJg.getXshgd());
            params.put("排水高度提供", jkSbJg.getPshgd());
            params.put("实际高度计算", jkSbJg.getShjgd());
            params.put("电机输入功率实测", jkSbJg.getDjshrgl());
            params.put("电机效率查询", jkSbJg.getDjxl());
            params.put("泵轴功率计算", jkSbJg.getBzhgl());
            params.put("转速实测", jkSbJg.getZhs());
            params.put("水泵输出功率计算", jkSbJg.getSbshcgl());
            params.put("管路效率计算", jkSbJg.getGlxl());
            params.put("系统效率计算", jkSbJg.getXtxl());
            params.put("吨水百米电耗计算", jkSbJg.getDshbmdh());
            params.put("振动烈度实测", jkSbJg.getZhdld());
            params.put("水泵房噪声实测", jkSbJg.getSbfzs());
            params.put("启动时间实测", jkSbJg.getQdshj());
            params.put("接地电阻实测", jkSbJg.getJddz());
        }
        //水泵工况参数点
        if(null != jkSbReportData.getJkSbGkList() && !jkSbReportData.getJkSbGkList().isEmpty()) {
            List<JkSbGk> jkSbGkList = jkSbReportData.getJkSbGkList();
            for(int i = 0 ; i < jkSbGkList.size(); i++) {
                if(StringUtils.isNotEmpty(jkSbGkList.get(i).getGkd())) {
                    params.put("流量" + jkSbGkList.get(i).getGkd(), jkSbGkList.get(i).getLl());
                    params.put("效率" + jkSbGkList.get(i).getGkd(), jkSbGkList.get(i).getXl());
                    params.put("扬程" + jkSbGkList.get(i).getGkd(), jkSbGkList.get(i).getYch());
                    params.put("轴功率" + jkSbGkList.get(i).getGkd(), jkSbGkList.get(i).getZhgl());
                }
            }
        }
        //电动机参数点
        if(null != jkSbReportData.getJkSbDjInfoList() && !jkSbReportData.getJkSbDjInfoList().isEmpty()) {
            List<JkSbDjInfo> jkSbDjInfoList = jkSbReportData.getJkSbDjInfoList();
            for(int i = 0 ; i < jkSbDjInfoList.size(); i++) {
                if(StringUtils.isNotEmpty(jkSbDjInfoList.get(i).getTjcs())) {
                    params.put("电动机转速" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getDdjzhs());
                    params.put("电压" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getDy());
                    params.put("电流" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getDl());
                    params.put("功率因数" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getGlysh());
                    params.put("电动机效率" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getDdjxl());
                    params.put("输入功率" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getShrgl());
                    params.put("输出功率" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getShcgl());
                    params.put("备注" + jkSbDjInfoList.get(i).getTjcs(), jkSbDjInfoList.get(i).getRemark());
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("建议", jkSbReportData.getJyi());
        if(null != jkSbReportData.getEquColReruReportList() && !jkSbReportData.getEquColReruReportList().isEmpty()) {
            params.put("检验用设备和仪器备注", jkSbReportData.getEquColReruReportList().get(0).getRemark());
        }
        if(null != jkSbReportData.getReportTestItemList() && !jkSbReportData.getReportTestItemList().isEmpty()) {
            params.put("检验项目备注", jkSbReportData.getReportTestItemList().get(0).getRemark());
        }
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkSbReportData.getReportNum() + "-jkSb.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 非煤防坠器数据保存
     *
     * @param jkFzqReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkFzq(JkFzqReportData jkFzqReportData) {
        //根据报告编号删除原数据
        delJkFzqInfoByReportNum(jkFzqReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkFzqReportData.getReportNum();
        String shjdw = jkFzqReportData.getReportBasicInfo().getShjdw();
        String jylb = jkFzqReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkFzqReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkFzqReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkFzqReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkFzqReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkFzqReportData.getSampleType());
        reportInformation.setEquName(jkFzqReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkFzqReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkFzqReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkFzqReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkFzqReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkFzqReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkFzqReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkFzqReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkFzqReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkFzqReportData.getEquColReruReportList() && !jkFzqReportData.getEquColReruReportList().isEmpty()) {
            jkFzqReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkFzqReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkFzqReportData.getReportTestInfo().setReportNum(reportNum);
            jkFzqReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkFzqReportData.getReportTestInfo().setJylb(jylb);
            jkFzqReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkFzqReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkFzqReportData.getReportTestItemList() && !jkFzqReportData.getReportTestItemList().isEmpty()) {
            jkFzqReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkFzqReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != jkFzqReportData.getJkFzqInfo()) {
            jkFzqReportData.getJkFzqInfo().setReportNum(reportNum);
            jkFzqReportData.getJkFzqInfo().setCpzt(jkFzqReportData.getCpzt());
            fzqInfoService.insertJkFzqInfo(jkFzqReportData.getJkFzqInfo());
        }
        return 1;
    }

    /**
     * 根据报告编号删除防坠器详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkFzqInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤防坠器参数信息
        fzqInfoService.deleteJkFzqInfoByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤防坠器报告导入
     *
     * @param jkFzqReportData
     */
    @Override
    public String importJkFzq(JkFzqReportData jkFzqReportData) {
        // 报告模板名称
        String template = jkFzqReportData.getTempId();
        //保存结果内容
        saveJkFzq(jkFzqReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkFzqReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkFzqReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkFzqReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkFzqReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkFzqReportData.getReportTestInfo();
            params.put("设备名称", jkFzqReportData.getReportBasicInfo().getShbmc());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkFzqReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("报告检验日期", DateUtils.formatDate(jkFzqReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("受检单位名称", jkFzqReportData.getReportBasicInfo().getShjdw());
            params.put("规格型号", jkFzqReportData.getReportBasicInfo().getXhgg());
            params.put("产品状态", jkFzqReportData.getCpzt());
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("生产厂家", reportTestinfo.getZhzdw());
            params.put("检验地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkFzqReportData.getReportHj()) {
            ReportHj reportHj = jkFzqReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkFzqReportData.getEquColReruReportList() && !jkFzqReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkFzqReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkFzqReportData.getJkFzqInfo()) {
            JkFzqInfo jkFzqInfo = jkFzqReportData.getJkFzqInfo();
            params.put("防坠器设备编号", jkFzqInfo.getShbbh());
            params.put("防坠器使用场所", jkFzqInfo.getShychs());
            params.put("防坠器类型", jkFzqInfo.getFzqlx());
            params.put("防坠器型号规格", jkFzqInfo.getXhgg());
            params.put("防坠器制造单位", jkFzqInfo.getZhzdw());
            params.put("防坠器抓捕器数量", jkFzqInfo.getZhbqshl());
            params.put("防坠器最大终端载荷", jkFzqInfo.getZdzhdzh());
            params.put("防坠器最小终端载荷", jkFzqInfo.getZxzhdzh());
            params.put("防坠器制动绳直径", jkFzqInfo.getZhdshzj());
            params.put("防坠器缓冲绳直径", jkFzqInfo.getHchszj());
        }
        //检测检验项目表
        if(null != jkFzqReportData.getReportTestItemList() && !jkFzqReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkFzqReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put((i + 1) + "实测结果", reportTestItemList.get(i).getShcjg());
                    if(StringUtils.isNotEmpty(reportTestItemList.get(i).getPdjg())) {
                        params.put((i + 1) + "判定", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                    }
                    params.put((i + 1) + "备注", reportTestItemList.get(i).getRemark());
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("建议", jkFzqReportData.getJyi());
        params.put("检验用设备和仪器备注", jkFzqReportData.getEquColReruReportList().get(0).getRemark());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkFzqReportData.getReportNum() + "-jkFzq.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 非煤带式输送机数据保存
     *
     * @param jkDshshsjReportData
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveJkDshshsj(JkDshshsjReportData jkDshshsjReportData) {
        //根据报告编号删除原数据
        delJkDshshsjInfoByReportNum(jkDshshsjReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkDshshsjReportData.getReportNum();
        String shjdw = jkDshshsjReportData.getReportBasicInfo().getShjdw();
        String jylb = jkDshshsjReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkDshshsjReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkDshshsjReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkDshshsjReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkDshshsjReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkDshshsjReportData.getSampleType());
        reportInformation.setEquName(jkDshshsjReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkDshshsjReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkDshshsjReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkDshshsjReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkDshshsjReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkDshshsjReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkDshshsjReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkDshshsjReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkDshshsjReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkDshshsjReportData.getEquColReruReportList() && !jkDshshsjReportData.getEquColReruReportList().isEmpty()) {
            jkDshshsjReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkDshshsjReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkDshshsjReportData.getReportTestInfo().setReportNum(reportNum);
            jkDshshsjReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkDshshsjReportData.getReportTestInfo().setJylb(jylb);
            jkDshshsjReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkDshshsjReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkDshshsjReportData.getReportTestItemList() && !jkDshshsjReportData.getReportTestItemList().isEmpty()) {
            jkDshshsjReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkDshshsjReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        //保存主要技术参数
        if(null != jkDshshsjReportData.getJkDshshsjInfo()) {
            jkDshshsjReportData.getJkDshshsjInfo().setReportNum(reportNum);
            jkDshshsjInfoService.insertJkDshshsjInfo(jkDshshsjReportData.getJkDshshsjInfo());
        }
        //保存电机参数
        if(null != jkDshshsjReportData.getJkDshshsjDjInfoList() && !jkDshshsjReportData.getJkDshshsjDjInfoList().isEmpty()) {
            jkDshshsjReportData.getJkDshshsjDjInfoList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            jkDshshsjDjInfoService.batchJkDshshsjDjInfo(jkDshshsjReportData.getJkDshshsjDjInfoList());
        }
        return 1;
    }

    /**
     * 根据报告编号删除带式输送机详细信息
     *
     * @param reportNum
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delJkDshshsjInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除非煤输送机电机参数信息
        jkDshshsjDjInfoService.deleteJkDshshsjDjInfoByReportNum(reportNum);
        //根据报告编号删除非煤输送机信息
        jkDshshsjInfoService.deleteJkDshshsjInfoByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤带式输送机报告导入
     *
     * @param jkDshshsjReportData
     */
    @Override
    public String importJkDshshsj(JkDshshsjReportData jkDshshsjReportData) {
        // 报告模板名称
        String template = jkDshshsjReportData.getTempId();
        //保存结果内容
        saveJkDshshsj(jkDshshsjReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkDshshsjReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkDshshsjReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkDshshsjReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkDshshsjReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkDshshsjReportData.getReportTestInfo();
            params.put("设备型号", jkDshshsjReportData.getReportBasicInfo().getXhgg());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkDshshsjReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("报告检测日期", DateUtils.formatDate(jkDshshsjReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("制造单位", reportTestinfo.getZhzdw());
            params.put("检测地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位名称", jkDshshsjReportData.getReportBasicInfo().getShjdw());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkDshshsjReportData.getReportHj()) {
            ReportHj reportHj = jkDshshsjReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("环境检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkDshshsjReportData.getEquColReruReportList() && !jkDshshsjReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkDshshsjReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //主要技术参数信息
        if(null != jkDshshsjReportData.getJkDshshsjInfo()) {
            JkDshshsjInfo jkDshshsjInfo = jkDshshsjReportData.getJkDshshsjInfo();
            params.put("输送机型号", jkDshshsjInfo.getShsjxh());
            params.put("带速", jkDshshsjInfo.getDs());
            params.put("胶带宽", jkDshshsjInfo.getJdk());
            params.put("皮带长度", jkDshshsjInfo.getPdcd());
            params.put("皮带机出厂日期", DateUtils.formatDate(jkDshshsjInfo.getPdjchcrq(), DateUtils.CYYYY_MM_DD));
            params.put("皮带机出厂编号", jkDshshsjInfo.getPdjchcbh());
            params.put("皮带机生产厂家", jkDshshsjInfo.getPdjshcchj());
            params.put("输送量", jkDshshsjInfo.getShsl());
            params.put("倾角", jkDshshsjInfo.getQj());
            params.put("皮带机安标证号", jkDshshsjInfo.getPdjabzhh());
            params.put("电机型号", jkDshshsjInfo.getDjxh());
            params.put("电机额定功率", jkDshshsjInfo.getDjedgl());
            params.put("电机额定电压", jkDshshsjInfo.getDjeddy());
            params.put("电机额定电流", jkDshshsjInfo.getDjeddl());
            params.put("电机转速", jkDshshsjInfo.getDjzhs());
            params.put("电机出厂编号", jkDshshsjInfo.getDjchcbh());
            params.put("电机生产日期", DateUtils.formatDate(jkDshshsjInfo.getDjshcrq(), DateUtils.CYYYY_MM_DD));
            params.put("电机生产厂家", jkDshshsjInfo.getDjshccj());
            params.put("电机接法", jkDshshsjInfo.getDjjf());
            params.put("电机绝缘等级", jkDshshsjInfo.getDjjydj());
            params.put("电机安标证号", jkDshshsjInfo.getDjabzhh());
            params.put("电机防爆合格证", jkDshshsjInfo.getDjfbhgzh());
            params.put("耦合器型号", jkDshshsjInfo.getOhqxh());
            params.put("耦合器出厂编号", jkDshshsjInfo.getOhqchcbh());
            params.put("耦合器功率范围", jkDshshsjInfo.getOhqglfw());
            params.put("耦合器输入转速", jkDshshsjInfo.getOhqshrzhs());
            params.put("耦合器调速范围", jkDshshsjInfo.getOhqtsfw());
            params.put("耦合器额定转差率", jkDshshsjInfo.getOhqedzhcl());
            params.put("耦合器生产厂家", jkDshshsjInfo.getOhqshchcj());
            params.put("耦合器出厂日期", DateUtils.formatDate(jkDshshsjInfo.getOhqchcrq(), DateUtils.CYYYY_MM_DD));
            params.put("耦合器安标证号", jkDshshsjInfo.getOhqabzhh());
            params.put("耦合器防爆合格证", jkDshshsjInfo.getOhqfbhgzh());
            params.put("减速箱型号", jkDshshsjInfo.getJsxxh());
            params.put("减速箱速比", jkDshshsjInfo.getJsxsb());
            params.put("输送带型号", jkDshshsjInfo.getShsdxh());
        }
        //检测检验项目表
        if(null != jkDshshsjReportData.getReportTestItemList() && !jkDshshsjReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkDshshsjReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put((i + 1) + "实测结果", reportTestItemList.get(i).getShcjg());
                    if(StringUtils.isNotEmpty(reportTestItemList.get(i).getPdjg())) {
                        params.put((i + 1) + "判定结果", DictUtils.getDictLabel("report_result", reportTestItemList.get(i).getPdjg(), ""));
                    }
                    params.put((i + 1) + "备注", reportTestItemList.get(i).getRemark());
                }
            }
        }
        //电动机参数点
        List<Map<String, Object>> djList = new ArrayList<>();
        if(null != jkDshshsjReportData.getJkDshshsjDjInfoList() && !jkDshshsjReportData.getJkDshshsjDjInfoList().isEmpty()) {
            List<JkDshshsjDjInfo> jkDshshsjDjInfoList = jkDshshsjReportData.getJkDshshsjDjInfoList();
            for(int i = 0 ; i < jkDshshsjDjInfoList.size(); i++) {
                Map<String, Object> djMap = new HashMap<>();
                if(StringUtils.isNotEmpty(jkDshshsjDjInfoList.get(i).getTjcs())) {
                    djMap.put("调节次数", jkDshshsjDjInfoList.get(i).getTjcs());
                    djMap.put("电动机转速", jkDshshsjDjInfoList.get(i).getDdjzhs());
                    djMap.put("电压", jkDshshsjDjInfoList.get(i).getDy());
                    djMap.put("电流", jkDshshsjDjInfoList.get(i).getDl());
                    djMap.put("功率因数", jkDshshsjDjInfoList.get(i).getGlysh());
                    djMap.put("电动机效率", jkDshshsjDjInfoList.get(i).getDdjxl());
                    djMap.put("输入功率", jkDshshsjDjInfoList.get(i).getShrgl());
                    djMap.put("输出功率", jkDshshsjDjInfoList.get(i).getShcgl());
                    djMap.put("备注", jkDshshsjDjInfoList.get(i).getRemark());
                }
                djList.add(djMap);
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("电机参数数据List", djList);
        params.put("建议", jkDshshsjReportData.getJyi());
        params.put("检验用设备和仪器备注", jkDshshsjReportData.getEquColReruReportList().get(0).getRemark());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkDshshsjReportData.getReportNum() + "-jkDshshsj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 非煤地下矿山监测监控系统数据保存
     *
     * @param jkKshjcjkxtReportData
     */
    @Override
    public int saveJkKshjcjkxt(JkKshjcjkxtReportData jkKshjcjkxtReportData) {
        //根据报告编号删除原数据
        delJkKshjcjkxtInfoByReportNum(jkKshjcjkxtReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = jkKshjcjkxtReportData.getReportNum();
        String shjdw = jkKshjcjkxtReportData.getReportBasicInfo().getShjdw();
        String jylb = jkKshjcjkxtReportData.getReportBasicInfo().getJcjylx();
        Date jcjyrq = jkKshjcjkxtReportData.getReportBasicInfo().getJcjyrq();
        String jyi = jkKshjcjkxtReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(jkKshjcjkxtReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(jkKshjcjkxtReportData.getAgreementNum().split("-")[0]);
        reportInformation.setSampleType(jkKshjcjkxtReportData.getSampleType());
        reportInformation.setEquName(jkKshjcjkxtReportData.getReportBasicInfo().getShbmc());
        reportInformation.setEquModel(jkKshjcjkxtReportData.getReportBasicInfo().getXhgg());
        reportInformation.setTestMethod(jkKshjcjkxtReportData.getReportBasicInfo().getJcjylx());
        reportInformation.setTester(jkKshjcjkxtReportData.getReportTestInfo().getJyry());
        reportInformation.setTestDate(jkKshjcjkxtReportData.getReportTestInfo().getJcrq());
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            jkKshjcjkxtReportData.getReportBasicInfo().setReportNum(reportNum);
            reportBasicinfoService.insertReportBasicinfo(jkKshjcjkxtReportData.getReportBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            jkKshjcjkxtReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(jkKshjcjkxtReportData.getReportHj());
        }
        //设备信息保存
        if(null != jkKshjcjkxtReportData.getEquColReruReportList() && !jkKshjcjkxtReportData.getEquColReruReportList().isEmpty()) {
            jkKshjcjkxtReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(jkKshjcjkxtReportData.getEquColReruReportList());
        }
        //保存检测检验报告信息
        if(null != reportNum) {
            jkKshjcjkxtReportData.getReportTestInfo().setReportNum(reportNum);
            jkKshjcjkxtReportData.getReportTestInfo().setShjdwmc(shjdw);
            jkKshjcjkxtReportData.getReportTestInfo().setJylb(jylb);
            jkKshjcjkxtReportData.getReportTestInfo().setJcrq(jcjyrq);
            reportTestinfoService.insertReportTestinfo(jkKshjcjkxtReportData.getReportTestInfo());
        }
        //保存检测检验项信息
        if(null != jkKshjcjkxtReportData.getReportTestItemList() && !jkKshjcjkxtReportData.getReportTestItemList().isEmpty()) {
            jkKshjcjkxtReportData.getReportTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            List<ReportTestItem> reportTestItemList = jkKshjcjkxtReportData.getReportTestItemList().stream().filter(e -> e.getShcjg() != null).collect(Collectors.toList());
            reportTestItemService.batchReportTestItem(reportTestItemList);
        }
        return 1;
    }

    /**
     * 根据报告编号删除地下矿山监测监控系统详细信息
     *
     * @param reportNum
     */
    @Override
    public int delJkKshjcjkxtInfoByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        reportBasicinfoService.deleteReportBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验报告信息
        reportTestinfoService.deleteReportTestinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除检测项信息
        reportTestItemService.deleteReportTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 非煤地下矿山监测监控系统报告导入
     *
     * @param jkKshjcjkxtReportData
     */
    @Override
    public String importJkKshjcjkxt(JkKshjcjkxtReportData jkKshjcjkxtReportData) {
        // 报告模板名称
        String template = jkKshjcjkxtReportData.getTempId();
        //保存结果内容
        saveJkKshjcjkxt(jkKshjcjkxtReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != jkKshjcjkxtReportData.getReportBasicInfo()) {
            ReportBasicinfo reportBasicinfo = jkKshjcjkxtReportData.getReportBasicInfo();
            params.put("受检单位", reportBasicinfo.getShjdw());
            params.put("设备名称", reportBasicinfo.getShbmc());
            params.put("使用地点", reportBasicinfo.getShydd());
            params.put("型号规格", reportBasicinfo.getXhgg());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", reportBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(reportBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
        }
        //报告编号
        params.put("报告编号", jkKshjcjkxtReportData.getReportNum());
        //检测检验报告表信息
        if(null != jkKshjcjkxtReportData.getReportTestInfo()) {
            ReportTestinfo reportTestinfo = jkKshjcjkxtReportData.getReportTestInfo();
            params.put("设备型号", jkKshjcjkxtReportData.getReportBasicInfo().getXhgg());
            params.put("检验类别", DictUtils.getDictLabel("report_test_category", jkKshjcjkxtReportData.getReportBasicInfo().getJcjylx(), ""));
            params.put("设备用途", reportTestinfo.getShbyt());
            params.put("报告检测日期", DateUtils.formatDate(jkKshjcjkxtReportData.getReportBasicInfo().getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("制造单位", reportTestinfo.getZhzdw());
            params.put("检测地点", reportTestinfo.getJcdd());
            params.put("出厂日期", DateUtils.formatDate(reportTestinfo.getChcrq(), DateUtils.YYYY_MM_DD));
            params.put("设备编号", reportTestinfo.getShbbh());
            params.put("受检单位名称", jkKshjcjkxtReportData.getReportBasicInfo().getShjdw());
            params.put("受检单位地址", reportTestinfo.getShjdwdz());
            params.put("检验结论", DictUtils.getDictLabel("report_result", reportTestinfo.getJcjl(), ""));
            params.put("签发日期", DateUtils.formatDate(reportTestinfo.getQfrq(), DateUtils.CYYYY_MM_DD));
            params.put("检验人员", reportTestinfo.getJyry());
            params.put("备注", reportTestinfo.getRemark());
        }
        //检测检验环境表信息
        if(null != jkKshjcjkxtReportData.getReportHj()) {
            ReportHj reportHj = jkKshjcjkxtReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("气压", reportHj.getDaqy());
            params.put("环境检测地点", reportHj.getJcdd());
            params.put("环境检测日期", DateUtils.formatDate(reportHj.getJcrq(), DateUtils.CYYYY_MM_DD));
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != jkKshjcjkxtReportData.getEquColReruReportList() && !jkKshjcjkxtReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = jkKshjcjkxtReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("设备唯一性编号", equColReruReportList.get(i).getEquNum());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("最大允许误差/准确度等级/不确定度", equColReruReportList.get(i).getEquGrade());
                equMap.put("检定/校准证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //检测检验项目表
        if(null != jkKshjcjkxtReportData.getReportTestItemList() && !jkKshjcjkxtReportData.getReportTestItemList().isEmpty()) {
            List<ReportTestItem> reportTestItemList = jkKshjcjkxtReportData.getReportTestItemList();
            for(int i = 0 ; i < reportTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(reportTestItemList.get(i).getShcjg())) {
                    params.put((i + 1) + "实测结果", reportTestItemList.get(i).getShcjg());
                    params.put((i + 1) + "备注", reportTestItemList.get(i).getRemark());
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        params.put("建议", jkKshjcjkxtReportData.getJyi());
        params.put("检验用设备和仪器备注", jkKshjcjkxtReportData.getEquColReruReportList().get(0).getRemark());
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + jkKshjcjkxtReportData.getReportNum() + "-jkKshjcjkxt.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }

    /**
     * 传感器数据保存
     *
     * @param ybReportData
     */
    @Override
    public int saveCgq(YbReportData ybReportData) {
        //根据报告编号删除原数据
        delCgqByReportNum(ybReportData.getReportNum());
        //获取报告编号、检验类别、受检单位、检测日期
        String reportNum = ybReportData.getReportNum();
        String shjdw = ybReportData.getYbBasicInfo().getShjdw();
        String jylb = ybReportData.getYbBasicInfo().getJcjylx();
        Date jcjyrq = ybReportData.getYbBasicInfo().getJcjyrq();
        String jyi = ybReportData.getJyi();
        //报告信息保存
        ReportInformation reportInformation = new ReportInformation();
        reportInformation.setId(IdUtils.fastSimpleUUID());
        reportInformation.setAgreementNum(ybReportData.getAgreementNum());
        reportInformation.setReportNum(reportNum);
        reportInformation.setClient(shjdw);
        reportInformation.setReportType(DictUtils.getDictLabel("item_type", "CGQ", ""));
        reportInformation.setSampleType(ybReportData.getSampleType());
        reportInformation.setEquName(ybReportData.getYbBasicInfo().getShbmc());
        reportInformation.setEquModel(ybReportData.getYbBasicInfo().getXhgg());
        reportInformation.setTestMethod(ybReportData.getYbBasicInfo().getJcjylx());
        //reportInformation.setTester(ybReportData.getYbBasicInfo().getJyry());
        reportInformation.setTestDate(jcjyrq);
        reportInformation.setRemark(jyi);
        reportInformation.setUploadType("2");
        reportInformation.setState("1");
        reportInformationService.insertReportInformation(reportInformation);
        //保存基本信息结果
        if(null != reportNum) {
            ybReportData.getYbBasicInfo().setReportNum(reportNum);
            ybBasicinfoService.insertYbBasicinfo(ybReportData.getYbBasicInfo());
        }
        //保存环境参数
        if(null != reportNum) {
            ybReportData.getReportHj().setReportNum(reportNum);
            reportHjService.insertReportHj(ybReportData.getReportHj());
        }
        //设备信息保存
        if(null != ybReportData.getEquColReruReportList() && !ybReportData.getEquColReruReportList().isEmpty()) {
            ybReportData.getEquColReruReportList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            equColrerureportService.batchEquColrerureport(ybReportData.getEquColReruReportList());
        }
        //保存检测检验项信息
        if(null != ybReportData.getYbTestItemList() && !ybReportData.getYbTestItemList().isEmpty()) {
            ybReportData.getYbTestItemList().forEach(item -> {
                item.setReportNum(reportNum);
            });
            ybTestItemService.batchYbTestItem(ybReportData.getYbTestItemList());
        }
        return 1;
    }

    /**
     * 根据报告编号传感器详细信息
     *
     * @param reportNum
     */
    @Override
    public int delCgqByReportNum(String reportNum) {
        //根据报告编号删除报告基本信息
        reportInformationService.deleteReportInformationByReportNum(reportNum);
        //根据报告编号删除基本信息
        ybBasicinfoService.deleteYbBasicinfoByReportNum(reportNum);
        //根据报告编号删除检测检验环境信息
        reportHjService.deleteReportHjByReportNum(reportNum);
        //根据报告编号删除检测检验设备仪器信息
        equColrerureportService.deleteEquColrerureportByReportNum(reportNum);
        //根据报告编号删除检测项信息
        ybTestItemService.deleteYbTestItemByReportNum(reportNum);
        return 1;
    }

    /**
     * 传感器报告导入
     *
     * @param ybReportData
     */
    @Override
    public String importCgq(YbReportData ybReportData) {
        // 报告模板名称
        String template = ybReportData.getTempId();
        //保存结果内容
        saveCgq(ybReportData);
        //导入报告信息
        Map<String, Object> params = new HashMap<>();
        //基本检测信息
        if(null != ybReportData.getYbBasicInfo()) {
            YbBasicinfo ybBasicinfo = ybReportData.getYbBasicInfo();
            params.put("受检单位", ybBasicinfo.getShjdw());
            params.put("设备名称", ybBasicinfo.getShbmc());
            params.put("型号规格", ybBasicinfo.getXhgg());
            params.put("出厂编号", ybBasicinfo.getChchbh());
            params.put("制造单位", ybBasicinfo.getZhzdw());
            params.put("检验依据", ybBasicinfo.getJyyj());
            params.put("检测检验类型", DictUtils.getDictLabel("report_test_category", ybBasicinfo.getJcjylx(), ""));
            params.put("检测检验日期", DateUtils.formatDate(ybBasicinfo.getJcjyrq(), DateUtils.YYYY_MM_DD));
            params.put("有效期至", DateUtils.formatDate(ybBasicinfo.getYxqz(), DateUtils.YYYY_MM_DD));
            params.put("检验结论", ybBasicinfo.getJyjl());
        }
        //报告编号
        params.put("报告编号", ybReportData.getReportNum());
        //检测检验环境表信息
        if(null != ybReportData.getReportHj()) {
            ReportHj reportHj = ybReportData.getReportHj();
            params.put("温度", reportHj.getWendu());
            params.put("湿度", reportHj.getXdshd());
            params.put("检测地点", reportHj.getJcdd());
        }
        //检测用设备和仪器信息
        List<Map<String, Object>> equList = new ArrayList<>();
        if(null != ybReportData.getEquColReruReportList() && !ybReportData.getEquColReruReportList().isEmpty()) {
            List<EquColReruReport> equColReruReportList = ybReportData.getEquColReruReportList();
            for(int i = 0 ; i < equColReruReportList.size(); i++) {
                Map<String, Object> equMap = new HashMap<>();
                equMap.put("序号", i + 1);
                equMap.put("名称", equColReruReportList.get(i).getEquName());
                equMap.put("型号规格", equColReruReportList.get(i).getEquModel());
                equMap.put("检定证书编号", equColReruReportList.get(i).getEquCertificate());
                equList.add(equMap);
            }
        }
        //检测检验项目表
        if(null != ybReportData.getYbTestItemList() && !ybReportData.getYbTestItemList().isEmpty()) {
            List<YbTestItem> ybTestItemList = ybReportData.getYbTestItemList();
            for(int i = 0 ; i < ybTestItemList.size(); i++) {
                if(StringUtils.isNotEmpty(ybTestItemList.get(i).getShcjg())) {
                    params.put("实测值"  + (i + 1), ybTestItemList.get(i).getShcjg());
                    params.put("误差值"  + (i + 1), ybTestItemList.get(i).getWcjg());
                    params.put("单项判定" + (i + 1), DictUtils.getDictLabel("report_result", ybTestItemList.get(i).getPdjg(), ""));
                }
            }
        }
        params.put("检验用设备和仪器数据List", equList);
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-" + ybReportData.getReportNum() + "-" + StringUtils.lowerCase(ybReportData.getSampleType()) + ".docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }


}
